{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>对手</th>\n",
       "      <th>胜负</th>\n",
       "      <th>主客场</th>\n",
       "      <th>命中</th>\n",
       "      <th>投篮数</th>\n",
       "      <th>投篮命中率</th>\n",
       "      <th>3分命中率</th>\n",
       "      <th>篮板</th>\n",
       "      <th>助攻</th>\n",
       "      <th>得分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>步行者</td>\n",
       "      <td>胜</td>\n",
       "      <td>主</td>\n",
       "      <td>8</td>\n",
       "      <td>22</td>\n",
       "      <td>0.364</td>\n",
       "      <td>0.333</td>\n",
       "      <td>8</td>\n",
       "      <td>10</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>湖人</td>\n",
       "      <td>胜</td>\n",
       "      <td>客</td>\n",
       "      <td>13</td>\n",
       "      <td>22</td>\n",
       "      <td>0.591</td>\n",
       "      <td>0.444</td>\n",
       "      <td>4</td>\n",
       "      <td>9</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>爵士</td>\n",
       "      <td>胜</td>\n",
       "      <td>客</td>\n",
       "      <td>8</td>\n",
       "      <td>19</td>\n",
       "      <td>0.421</td>\n",
       "      <td>0.333</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>开拓者</td>\n",
       "      <td>胜</td>\n",
       "      <td>客</td>\n",
       "      <td>16</td>\n",
       "      <td>29</td>\n",
       "      <td>0.552</td>\n",
       "      <td>0.571</td>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>鹈鹕</td>\n",
       "      <td>胜</td>\n",
       "      <td>主</td>\n",
       "      <td>8</td>\n",
       "      <td>16</td>\n",
       "      <td>0.500</td>\n",
       "      <td>0.400</td>\n",
       "      <td>1</td>\n",
       "      <td>17</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     对手 胜负 主客场  命中  投篮数  投篮命中率  3分命中率  篮板  助攻  得分\n",
       "20  步行者  胜   主   8   22  0.364  0.333   8  10  29\n",
       "21   湖人  胜   客  13   22  0.591  0.444   4   9  36\n",
       "22   爵士  胜   客   8   19  0.421  0.333   5   3  29\n",
       "23  开拓者  胜   客  16   29  0.552  0.571   8   3  48\n",
       "24   鹈鹕  胜   主   8   16  0.500  0.400   1  17  26"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('examples/James_Harden.csv',encoding='utf8')\n",
    "df.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>3分命中率</th>\n",
       "      <th>助攻</th>\n",
       "      <th>命中</th>\n",
       "      <th>得分</th>\n",
       "      <th>投篮命中率</th>\n",
       "      <th>投篮数</th>\n",
       "      <th>篮板</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>对手</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>76人</th>\n",
       "      <td>0.33950</td>\n",
       "      <td>10.00</td>\n",
       "      <td>9.0</td>\n",
       "      <td>28.00</td>\n",
       "      <td>0.4405</td>\n",
       "      <td>20.5</td>\n",
       "      <td>3.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>勇士</th>\n",
       "      <td>0.44400</td>\n",
       "      <td>11.00</td>\n",
       "      <td>10.0</td>\n",
       "      <td>27.00</td>\n",
       "      <td>0.4350</td>\n",
       "      <td>23.0</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>国王</th>\n",
       "      <td>0.28600</td>\n",
       "      <td>9.00</td>\n",
       "      <td>8.0</td>\n",
       "      <td>27.00</td>\n",
       "      <td>0.3810</td>\n",
       "      <td>21.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>太阳</th>\n",
       "      <td>0.54500</td>\n",
       "      <td>7.00</td>\n",
       "      <td>12.0</td>\n",
       "      <td>48.00</td>\n",
       "      <td>0.5450</td>\n",
       "      <td>22.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>小牛</th>\n",
       "      <td>0.46200</td>\n",
       "      <td>7.00</td>\n",
       "      <td>10.0</td>\n",
       "      <td>29.00</td>\n",
       "      <td>0.5260</td>\n",
       "      <td>19.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>尼克斯</th>\n",
       "      <td>0.36900</td>\n",
       "      <td>9.50</td>\n",
       "      <td>10.5</td>\n",
       "      <td>34.00</td>\n",
       "      <td>0.4175</td>\n",
       "      <td>25.0</td>\n",
       "      <td>3.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>开拓者</th>\n",
       "      <td>0.57100</td>\n",
       "      <td>3.00</td>\n",
       "      <td>16.0</td>\n",
       "      <td>48.00</td>\n",
       "      <td>0.5520</td>\n",
       "      <td>29.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>掘金</th>\n",
       "      <td>0.14300</td>\n",
       "      <td>9.00</td>\n",
       "      <td>6.0</td>\n",
       "      <td>21.00</td>\n",
       "      <td>0.3750</td>\n",
       "      <td>16.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>步行者</th>\n",
       "      <td>0.29150</td>\n",
       "      <td>12.50</td>\n",
       "      <td>8.5</td>\n",
       "      <td>27.50</td>\n",
       "      <td>0.3965</td>\n",
       "      <td>21.5</td>\n",
       "      <td>6.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖人</th>\n",
       "      <td>0.44400</td>\n",
       "      <td>9.00</td>\n",
       "      <td>13.0</td>\n",
       "      <td>36.00</td>\n",
       "      <td>0.5910</td>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>灰熊</th>\n",
       "      <td>0.35025</td>\n",
       "      <td>7.75</td>\n",
       "      <td>8.5</td>\n",
       "      <td>27.25</td>\n",
       "      <td>0.4015</td>\n",
       "      <td>21.0</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>爵士</th>\n",
       "      <td>0.60400</td>\n",
       "      <td>8.00</td>\n",
       "      <td>13.5</td>\n",
       "      <td>42.50</td>\n",
       "      <td>0.5905</td>\n",
       "      <td>22.0</td>\n",
       "      <td>3.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>猛龙</th>\n",
       "      <td>0.27300</td>\n",
       "      <td>11.00</td>\n",
       "      <td>8.0</td>\n",
       "      <td>38.00</td>\n",
       "      <td>0.3200</td>\n",
       "      <td>25.0</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>篮网</th>\n",
       "      <td>0.61500</td>\n",
       "      <td>8.00</td>\n",
       "      <td>13.0</td>\n",
       "      <td>37.00</td>\n",
       "      <td>0.6500</td>\n",
       "      <td>20.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>老鹰</th>\n",
       "      <td>0.54500</td>\n",
       "      <td>11.00</td>\n",
       "      <td>8.0</td>\n",
       "      <td>29.00</td>\n",
       "      <td>0.5330</td>\n",
       "      <td>15.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>骑士</th>\n",
       "      <td>0.42900</td>\n",
       "      <td>13.00</td>\n",
       "      <td>8.0</td>\n",
       "      <td>35.00</td>\n",
       "      <td>0.3810</td>\n",
       "      <td>21.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>鹈鹕</th>\n",
       "      <td>0.40000</td>\n",
       "      <td>17.00</td>\n",
       "      <td>8.0</td>\n",
       "      <td>26.00</td>\n",
       "      <td>0.5000</td>\n",
       "      <td>16.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黄蜂</th>\n",
       "      <td>0.40000</td>\n",
       "      <td>11.00</td>\n",
       "      <td>8.0</td>\n",
       "      <td>27.00</td>\n",
       "      <td>0.4440</td>\n",
       "      <td>18.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       3分命中率     助攻    命中     得分   投篮命中率   投篮数    篮板\n",
       "对手                                                  \n",
       "76人  0.33950  10.00   9.0  28.00  0.4405  20.5   3.5\n",
       "勇士   0.44400  11.00  10.0  27.00  0.4350  23.0   6.0\n",
       "国王   0.28600   9.00   8.0  27.00  0.3810  21.0   3.0\n",
       "太阳   0.54500   7.00  12.0  48.00  0.5450  22.0   2.0\n",
       "小牛   0.46200   7.00  10.0  29.00  0.5260  19.0   3.0\n",
       "尼克斯  0.36900   9.50  10.5  34.00  0.4175  25.0   3.5\n",
       "开拓者  0.57100   3.00  16.0  48.00  0.5520  29.0   8.0\n",
       "掘金   0.14300   9.00   6.0  21.00  0.3750  16.0   8.0\n",
       "步行者  0.29150  12.50   8.5  27.50  0.3965  21.5   6.5\n",
       "湖人   0.44400   9.00  13.0  36.00  0.5910  22.0   4.0\n",
       "灰熊   0.35025   7.75   8.5  27.25  0.4015  21.0   4.5\n",
       "爵士   0.60400   8.00  13.5  42.50  0.5905  22.0   3.5\n",
       "猛龙   0.27300  11.00   8.0  38.00  0.3200  25.0   6.0\n",
       "篮网   0.61500   8.00  13.0  37.00  0.6500  20.0  10.0\n",
       "老鹰   0.54500  11.00   8.0  29.00  0.5330  15.0   3.0\n",
       "骑士   0.42900  13.00   8.0  35.00  0.3810  21.0  11.0\n",
       "鹈鹕   0.40000  17.00   8.0  26.00  0.5000  16.0   1.0\n",
       "黄蜂   0.40000  11.00   8.0  27.00  0.4440  18.0  10.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.pivot_table(df,index=['对手'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>3分命中率</th>\n",
       "      <th>助攻</th>\n",
       "      <th>命中</th>\n",
       "      <th>得分</th>\n",
       "      <th>投篮命中率</th>\n",
       "      <th>投篮数</th>\n",
       "      <th>篮板</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>对手</th>\n",
       "      <th>主客场</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">76人</th>\n",
       "      <th>主</th>\n",
       "      <td>0.4290</td>\n",
       "      <td>7.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0.381</td>\n",
       "      <td>21.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>客</th>\n",
       "      <td>0.2500</td>\n",
       "      <td>13.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0.500</td>\n",
       "      <td>20.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>勇士</th>\n",
       "      <th>客</th>\n",
       "      <td>0.4440</td>\n",
       "      <td>11.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0.435</td>\n",
       "      <td>23.0</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>国王</th>\n",
       "      <th>客</th>\n",
       "      <td>0.2860</td>\n",
       "      <td>9.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0.381</td>\n",
       "      <td>21.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>太阳</th>\n",
       "      <th>客</th>\n",
       "      <td>0.5450</td>\n",
       "      <td>7.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.545</td>\n",
       "      <td>22.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>小牛</th>\n",
       "      <th>主</th>\n",
       "      <td>0.4620</td>\n",
       "      <td>7.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0.526</td>\n",
       "      <td>19.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">尼克斯</th>\n",
       "      <th>主</th>\n",
       "      <td>0.3850</td>\n",
       "      <td>10.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>0.444</td>\n",
       "      <td>27.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>客</th>\n",
       "      <td>0.3530</td>\n",
       "      <td>9.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>31.0</td>\n",
       "      <td>0.391</td>\n",
       "      <td>23.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>开拓者</th>\n",
       "      <th>客</th>\n",
       "      <td>0.5710</td>\n",
       "      <td>3.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.552</td>\n",
       "      <td>29.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>掘金</th>\n",
       "      <th>主</th>\n",
       "      <td>0.1430</td>\n",
       "      <td>9.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.375</td>\n",
       "      <td>16.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">步行者</th>\n",
       "      <th>主</th>\n",
       "      <td>0.3330</td>\n",
       "      <td>10.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0.364</td>\n",
       "      <td>22.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>客</th>\n",
       "      <td>0.2500</td>\n",
       "      <td>15.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0.429</td>\n",
       "      <td>21.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖人</th>\n",
       "      <th>客</th>\n",
       "      <td>0.4440</td>\n",
       "      <td>9.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>0.591</td>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">灰熊</th>\n",
       "      <th>主</th>\n",
       "      <td>0.3395</td>\n",
       "      <td>8.0</td>\n",
       "      <td>9.5</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.420</td>\n",
       "      <td>22.5</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>客</th>\n",
       "      <td>0.3610</td>\n",
       "      <td>7.5</td>\n",
       "      <td>7.5</td>\n",
       "      <td>24.5</td>\n",
       "      <td>0.383</td>\n",
       "      <td>19.5</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">爵士</th>\n",
       "      <th>主</th>\n",
       "      <td>0.8750</td>\n",
       "      <td>13.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>0.760</td>\n",
       "      <td>25.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>客</th>\n",
       "      <td>0.3330</td>\n",
       "      <td>3.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0.421</td>\n",
       "      <td>19.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>猛龙</th>\n",
       "      <th>主</th>\n",
       "      <td>0.2730</td>\n",
       "      <td>11.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>0.320</td>\n",
       "      <td>25.0</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>篮网</th>\n",
       "      <th>主</th>\n",
       "      <td>0.6150</td>\n",
       "      <td>8.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>0.650</td>\n",
       "      <td>20.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>老鹰</th>\n",
       "      <th>客</th>\n",
       "      <td>0.5450</td>\n",
       "      <td>11.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0.533</td>\n",
       "      <td>15.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>骑士</th>\n",
       "      <th>主</th>\n",
       "      <td>0.4290</td>\n",
       "      <td>13.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0.381</td>\n",
       "      <td>21.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>鹈鹕</th>\n",
       "      <th>主</th>\n",
       "      <td>0.4000</td>\n",
       "      <td>17.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0.500</td>\n",
       "      <td>16.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黄蜂</th>\n",
       "      <th>客</th>\n",
       "      <td>0.4000</td>\n",
       "      <td>11.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0.444</td>\n",
       "      <td>18.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          3分命中率    助攻    命中    得分  投篮命中率   投篮数    篮板\n",
       "对手  主客场                                             \n",
       "76人 主    0.4290   7.0   8.0  29.0  0.381  21.0   4.0\n",
       "    客    0.2500  13.0  10.0  27.0  0.500  20.0   3.0\n",
       "勇士  客    0.4440  11.0  10.0  27.0  0.435  23.0   6.0\n",
       "国王  客    0.2860   9.0   8.0  27.0  0.381  21.0   3.0\n",
       "太阳  客    0.5450   7.0  12.0  48.0  0.545  22.0   2.0\n",
       "小牛  主    0.4620   7.0  10.0  29.0  0.526  19.0   3.0\n",
       "尼克斯 主    0.3850  10.0  12.0  37.0  0.444  27.0   2.0\n",
       "    客    0.3530   9.0   9.0  31.0  0.391  23.0   5.0\n",
       "开拓者 客    0.5710   3.0  16.0  48.0  0.552  29.0   8.0\n",
       "掘金  主    0.1430   9.0   6.0  21.0  0.375  16.0   8.0\n",
       "步行者 主    0.3330  10.0   8.0  29.0  0.364  22.0   8.0\n",
       "    客    0.2500  15.0   9.0  26.0  0.429  21.0   5.0\n",
       "湖人  客    0.4440   9.0  13.0  36.0  0.591  22.0   4.0\n",
       "灰熊  主    0.3395   8.0   9.5  30.0  0.420  22.5   4.5\n",
       "    客    0.3610   7.5   7.5  24.5  0.383  19.5   4.5\n",
       "爵士  主    0.8750  13.0  19.0  56.0  0.760  25.0   2.0\n",
       "    客    0.3330   3.0   8.0  29.0  0.421  19.0   5.0\n",
       "猛龙  主    0.2730  11.0   8.0  38.0  0.320  25.0   6.0\n",
       "篮网  主    0.6150   8.0  13.0  37.0  0.650  20.0  10.0\n",
       "老鹰  客    0.5450  11.0   8.0  29.0  0.533  15.0   3.0\n",
       "骑士  主    0.4290  13.0   8.0  35.0  0.381  21.0  11.0\n",
       "鹈鹕  主    0.4000  17.0   8.0  26.0  0.500  16.0   1.0\n",
       "黄蜂  客    0.4000  11.0   8.0  27.0  0.444  18.0  10.0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.pivot_table(df,index=['对手','主客场'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>3分命中率</th>\n",
       "      <th>助攻</th>\n",
       "      <th>命中</th>\n",
       "      <th>得分</th>\n",
       "      <th>投篮命中率</th>\n",
       "      <th>投篮数</th>\n",
       "      <th>篮板</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>主客场</th>\n",
       "      <th>对手</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"11\" valign=\"top\">主</th>\n",
       "      <th>76人</th>\n",
       "      <td>0.4290</td>\n",
       "      <td>7.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0.381</td>\n",
       "      <td>21.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>小牛</th>\n",
       "      <td>0.4620</td>\n",
       "      <td>7.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0.526</td>\n",
       "      <td>19.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>尼克斯</th>\n",
       "      <td>0.3850</td>\n",
       "      <td>10.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>0.444</td>\n",
       "      <td>27.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>掘金</th>\n",
       "      <td>0.1430</td>\n",
       "      <td>9.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.375</td>\n",
       "      <td>16.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>步行者</th>\n",
       "      <td>0.3330</td>\n",
       "      <td>10.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0.364</td>\n",
       "      <td>22.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>灰熊</th>\n",
       "      <td>0.3395</td>\n",
       "      <td>8.0</td>\n",
       "      <td>9.5</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.420</td>\n",
       "      <td>22.5</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>爵士</th>\n",
       "      <td>0.8750</td>\n",
       "      <td>13.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>0.760</td>\n",
       "      <td>25.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>猛龙</th>\n",
       "      <td>0.2730</td>\n",
       "      <td>11.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>0.320</td>\n",
       "      <td>25.0</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>篮网</th>\n",
       "      <td>0.6150</td>\n",
       "      <td>8.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>0.650</td>\n",
       "      <td>20.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>骑士</th>\n",
       "      <td>0.4290</td>\n",
       "      <td>13.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0.381</td>\n",
       "      <td>21.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>鹈鹕</th>\n",
       "      <td>0.4000</td>\n",
       "      <td>17.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0.500</td>\n",
       "      <td>16.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"12\" valign=\"top\">客</th>\n",
       "      <th>76人</th>\n",
       "      <td>0.2500</td>\n",
       "      <td>13.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0.500</td>\n",
       "      <td>20.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>勇士</th>\n",
       "      <td>0.4440</td>\n",
       "      <td>11.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0.435</td>\n",
       "      <td>23.0</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>国王</th>\n",
       "      <td>0.2860</td>\n",
       "      <td>9.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0.381</td>\n",
       "      <td>21.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>太阳</th>\n",
       "      <td>0.5450</td>\n",
       "      <td>7.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.545</td>\n",
       "      <td>22.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>尼克斯</th>\n",
       "      <td>0.3530</td>\n",
       "      <td>9.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>31.0</td>\n",
       "      <td>0.391</td>\n",
       "      <td>23.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>开拓者</th>\n",
       "      <td>0.5710</td>\n",
       "      <td>3.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.552</td>\n",
       "      <td>29.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>步行者</th>\n",
       "      <td>0.2500</td>\n",
       "      <td>15.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0.429</td>\n",
       "      <td>21.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖人</th>\n",
       "      <td>0.4440</td>\n",
       "      <td>9.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>0.591</td>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>灰熊</th>\n",
       "      <td>0.3610</td>\n",
       "      <td>7.5</td>\n",
       "      <td>7.5</td>\n",
       "      <td>24.5</td>\n",
       "      <td>0.383</td>\n",
       "      <td>19.5</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>爵士</th>\n",
       "      <td>0.3330</td>\n",
       "      <td>3.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0.421</td>\n",
       "      <td>19.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>老鹰</th>\n",
       "      <td>0.5450</td>\n",
       "      <td>11.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0.533</td>\n",
       "      <td>15.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黄蜂</th>\n",
       "      <td>0.4000</td>\n",
       "      <td>11.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0.444</td>\n",
       "      <td>18.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          3分命中率    助攻    命中    得分  投篮命中率   投篮数    篮板\n",
       "主客场 对手                                              \n",
       "主   76人  0.4290   7.0   8.0  29.0  0.381  21.0   4.0\n",
       "    小牛   0.4620   7.0  10.0  29.0  0.526  19.0   3.0\n",
       "    尼克斯  0.3850  10.0  12.0  37.0  0.444  27.0   2.0\n",
       "    掘金   0.1430   9.0   6.0  21.0  0.375  16.0   8.0\n",
       "    步行者  0.3330  10.0   8.0  29.0  0.364  22.0   8.0\n",
       "    灰熊   0.3395   8.0   9.5  30.0  0.420  22.5   4.5\n",
       "    爵士   0.8750  13.0  19.0  56.0  0.760  25.0   2.0\n",
       "    猛龙   0.2730  11.0   8.0  38.0  0.320  25.0   6.0\n",
       "    篮网   0.6150   8.0  13.0  37.0  0.650  20.0  10.0\n",
       "    骑士   0.4290  13.0   8.0  35.0  0.381  21.0  11.0\n",
       "    鹈鹕   0.4000  17.0   8.0  26.0  0.500  16.0   1.0\n",
       "客   76人  0.2500  13.0  10.0  27.0  0.500  20.0   3.0\n",
       "    勇士   0.4440  11.0  10.0  27.0  0.435  23.0   6.0\n",
       "    国王   0.2860   9.0   8.0  27.0  0.381  21.0   3.0\n",
       "    太阳   0.5450   7.0  12.0  48.0  0.545  22.0   2.0\n",
       "    尼克斯  0.3530   9.0   9.0  31.0  0.391  23.0   5.0\n",
       "    开拓者  0.5710   3.0  16.0  48.0  0.552  29.0   8.0\n",
       "    步行者  0.2500  15.0   9.0  26.0  0.429  21.0   5.0\n",
       "    湖人   0.4440   9.0  13.0  36.0  0.591  22.0   4.0\n",
       "    灰熊   0.3610   7.5   7.5  24.5  0.383  19.5   4.5\n",
       "    爵士   0.3330   3.0   8.0  29.0  0.421  19.0   5.0\n",
       "    老鹰   0.5450  11.0   8.0  29.0  0.533  15.0   3.0\n",
       "    黄蜂   0.4000  11.0   8.0  27.0  0.444  18.0  10.0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.pivot_table(df,index=['主客场','对手'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>助攻</th>\n",
       "      <th>得分</th>\n",
       "      <th>篮板</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>主客场</th>\n",
       "      <th>胜负</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">主</th>\n",
       "      <th>胜</th>\n",
       "      <td>10.555556</td>\n",
       "      <td>34.222222</td>\n",
       "      <td>5.444444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>负</th>\n",
       "      <td>8.666667</td>\n",
       "      <td>29.666667</td>\n",
       "      <td>5.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">客</th>\n",
       "      <th>胜</th>\n",
       "      <td>9.000000</td>\n",
       "      <td>32.000000</td>\n",
       "      <td>4.916667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>负</th>\n",
       "      <td>8.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>4.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               助攻         得分        篮板\n",
       "主客场 胜负                                \n",
       "主   胜   10.555556  34.222222  5.444444\n",
       "    负    8.666667  29.666667  5.000000\n",
       "客   胜    9.000000  32.000000  4.916667\n",
       "    负    8.000000  20.000000  4.000000"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.pivot_table(df,index=['主客场','胜负'],values=['得分','助攻','篮板'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"3\" halign=\"left\">sum</th>\n",
       "      <th colspan=\"3\" halign=\"left\">mean</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>助攻</th>\n",
       "      <th>得分</th>\n",
       "      <th>篮板</th>\n",
       "      <th>助攻</th>\n",
       "      <th>得分</th>\n",
       "      <th>篮板</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>主客场</th>\n",
       "      <th>胜负</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">主</th>\n",
       "      <th>胜</th>\n",
       "      <td>95</td>\n",
       "      <td>308</td>\n",
       "      <td>49</td>\n",
       "      <td>10.555556</td>\n",
       "      <td>34.222222</td>\n",
       "      <td>5.444444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>负</th>\n",
       "      <td>26</td>\n",
       "      <td>89</td>\n",
       "      <td>15</td>\n",
       "      <td>8.666667</td>\n",
       "      <td>29.666667</td>\n",
       "      <td>5.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">客</th>\n",
       "      <th>胜</th>\n",
       "      <td>108</td>\n",
       "      <td>384</td>\n",
       "      <td>59</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>32.000000</td>\n",
       "      <td>4.916667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>负</th>\n",
       "      <td>8</td>\n",
       "      <td>20</td>\n",
       "      <td>4</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>4.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        sum                mean                     \n",
       "         助攻   得分  篮板         助攻         得分        篮板\n",
       "主客场 胜负                                              \n",
       "主   胜    95  308  49  10.555556  34.222222  5.444444\n",
       "    负    26   89  15   8.666667  29.666667  5.000000\n",
       "客   胜   108  384  59   9.000000  32.000000  4.916667\n",
       "    负     8   20   4   8.000000  20.000000  4.000000"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.pivot_table(df,index=['主客场','胜负'],values=['得分','助攻','篮板'],aggfunc=[np.sum,np.mean])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"6\" halign=\"left\">mean</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">助攻</th>\n",
       "      <th colspan=\"2\" halign=\"left\">得分</th>\n",
       "      <th colspan=\"2\" halign=\"left\">篮板</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>主客场</th>\n",
       "      <th>主</th>\n",
       "      <th>客</th>\n",
       "      <th>主</th>\n",
       "      <th>客</th>\n",
       "      <th>主</th>\n",
       "      <th>客</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>对手</th>\n",
       "      <th>胜负</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">76人</th>\n",
       "      <th>胜</th>\n",
       "      <td>0</td>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>负</th>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>勇士</th>\n",
       "      <th>胜</th>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>国王</th>\n",
       "      <th>胜</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>太阳</th>\n",
       "      <th>胜</th>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>48</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>小牛</th>\n",
       "      <th>胜</th>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>尼克斯</th>\n",
       "      <th>胜</th>\n",
       "      <td>10</td>\n",
       "      <td>9</td>\n",
       "      <td>37</td>\n",
       "      <td>31</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>开拓者</th>\n",
       "      <th>胜</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>48</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>掘金</th>\n",
       "      <th>胜</th>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>步行者</th>\n",
       "      <th>胜</th>\n",
       "      <td>10</td>\n",
       "      <td>15</td>\n",
       "      <td>29</td>\n",
       "      <td>26</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖人</th>\n",
       "      <th>胜</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>36</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">灰熊</th>\n",
       "      <th>胜</th>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>38</td>\n",
       "      <td>29</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>负</th>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "      <td>22</td>\n",
       "      <td>20</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>爵士</th>\n",
       "      <th>胜</th>\n",
       "      <td>13</td>\n",
       "      <td>3</td>\n",
       "      <td>56</td>\n",
       "      <td>29</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>猛龙</th>\n",
       "      <th>负</th>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>篮网</th>\n",
       "      <th>胜</th>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>37</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>老鹰</th>\n",
       "      <th>胜</th>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>骑士</th>\n",
       "      <th>胜</th>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>35</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>鹈鹕</th>\n",
       "      <th>胜</th>\n",
       "      <td>17</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黄蜂</th>\n",
       "      <th>胜</th>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       mean                    \n",
       "         助攻      得分      篮板    \n",
       "主客场       主   客   主   客   主   客\n",
       "对手  胜负                         \n",
       "76人 胜     0  13   0  27   0   3\n",
       "    负     7   0  29   0   4   0\n",
       "勇士  胜     0  11   0  27   0   6\n",
       "国王  胜     0   9   0  27   0   3\n",
       "太阳  胜     0   7   0  48   0   2\n",
       "小牛  胜     7   0  29   0   3   0\n",
       "尼克斯 胜    10   9  37  31   2   5\n",
       "开拓者 胜     0   3   0  48   0   8\n",
       "掘金  胜     9   0  21   0   8   0\n",
       "步行者 胜    10  15  29  26   8   5\n",
       "湖人  胜     0   9   0  36   0   4\n",
       "灰熊  胜     8   7  38  29   4   5\n",
       "    负     8   8  22  20   5   4\n",
       "爵士  胜    13   3  56  29   2   5\n",
       "猛龙  负    11   0  38   0   6   0\n",
       "篮网  胜     8   0  37   0  10   0\n",
       "老鹰  胜     0  11   0  29   0   3\n",
       "骑士  胜    13   0  35   0  11   0\n",
       "鹈鹕  胜    17   0  26   0   1   0\n",
       "黄蜂  胜     0  11   0  27   0  10"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.pivot_table(df,index=['对手','胜负'],columns=['主客场'],values=['得分','助攻','篮板'],aggfunc=[np.mean],fill_value=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>助攻</th>\n",
       "      <th>得分</th>\n",
       "      <th>篮板</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>主客场</th>\n",
       "      <th>胜负</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">主</th>\n",
       "      <th>胜</th>\n",
       "      <td>10.555556</td>\n",
       "      <td>34.222222</td>\n",
       "      <td>5.444444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>负</th>\n",
       "      <td>8.666667</td>\n",
       "      <td>29.666667</td>\n",
       "      <td>5.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">客</th>\n",
       "      <th>胜</th>\n",
       "      <td>9.000000</td>\n",
       "      <td>32.000000</td>\n",
       "      <td>4.916667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>负</th>\n",
       "      <td>8.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>4.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               助攻         得分        篮板\n",
       "主客场 胜负                                \n",
       "主   胜   10.555556  34.222222  5.444444\n",
       "    负    8.666667  29.666667  5.000000\n",
       "客   胜    9.000000  32.000000  4.916667\n",
       "    负    8.000000  20.000000  4.000000"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.pivot_table(df,index=['主客场','胜负'],values=['得分','助攻','篮板'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\anaconda3\\lib\\site-packages\\ipykernel_launcher.py:1: FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>得分</th>\n",
       "      <th>助攻</th>\n",
       "      <th>篮板</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>主客场</th>\n",
       "      <th>胜负</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">主</th>\n",
       "      <th>胜</th>\n",
       "      <td>34.222222</td>\n",
       "      <td>10.555556</td>\n",
       "      <td>5.444444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>负</th>\n",
       "      <td>29.666667</td>\n",
       "      <td>8.666667</td>\n",
       "      <td>5.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">客</th>\n",
       "      <th>胜</th>\n",
       "      <td>32.000000</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>4.916667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>负</th>\n",
       "      <td>20.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>4.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               得分         助攻        篮板\n",
       "主客场 胜负                                \n",
       "主   胜   34.222222  10.555556  5.444444\n",
       "    负   29.666667   8.666667  5.000000\n",
       "客   胜   32.000000   9.000000  4.916667\n",
       "    负   20.000000   8.000000  4.000000"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(['主客场','胜负'])['得分','助攻','篮板'].agg('mean')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
